

use "$data/survey1_clean.dta", clear

gen high_trust_science=(trust_science==4) *100

foreach x in male highschool college working unemp student democrat republican{
replace `x' =`x'*100
}

**** Summary stastistics of knowledge ****
gen empt=.
label var empt " "
label var empt " "
gen demographics=. 
label var demographics "\textbf{Panel A: Demographics}" 
label var male "\%  Male"
label var age_35 "\%  Age < 35"
label var age_65 "Age > 64"
label var highschool "\% Highschool education"
label var college "\%  College eductation"
label var working "\% Currently working"
label var unemp "\%  Unemployed"
label var student "\%  Student"
label var democrat "\% Democrat"
label var republican "\%  Republican"
label var high_trust_science "\% High trust in science"


gen perceptions =. 
label var perceptions "\textbf{Panel B: Economic Anxieties}"
gen agree_severe_total = inlist(impact_1 , 4,5)*100
label var agree_severe_total "\% agree: world severely affected by coronavirus"
gen agree_severe_US = inlist(impact_2 , 4,5)*100
label var agree_severe_US "\% agree: US severely affected by coronavirus"
label var agree_severe_US "\% agree: US severely affected by coronavirus"


gen high_worry_corona_econ = inlist(worry_corona_econ , 3,4)*100
label var high_worry_corona_econ "\% worried about US economy"
gen high_worry_perecon = inlist(worry_perecon , 3,4)*100
label var high_worry_perecon "\% worried about personal econ. situation"


gen knowledge = .
label var knowledge "\textbf{Panel C: Coronavirus perceptions }"

label var perceived_mortality "Predicted  mortality rate"
label var perceived_contagion "Infectiousness (R0)"



tempfile main
save `main', replace

clear all
eststo clear
estimates drop _all

loc columns = 4

set obs 10
gen x = 1
gen y = 1

forval i = 1/`columns' {
	eststo col`i': reg x y
} 

loc count = 1

loc statnames ""
loc varlabels ""

/* Custom fill cells */



use `main', clear

foreach yvar of varlist demographics empt male age_35  highschool college working democrat republican high_trust_science empt{

	sum `yvar', d
	if `r(N)'!=0 {
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	cap: estadd loc thisstat`count' = string(`r(sd)', "%9.2f"): col2
	cap: estadd loc thisstat`count' = `r(N)' : col4
	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1

}

foreach yvar of varlist perceptions empt agree_severe_total agree_severe_US  high_worry_corona_econ high_worry_perecon empt{

	sum `yvar', d
	if `r(N)'!=0 {
	cap: estadd loc thisstat`count' = string(`r(mean)', "%9.2f"): col1
	cap: estadd loc thisstat`count' = string(`r(sd)', "%9.2f"): col2
	cap: estadd loc thisstat`count' = `r(N)' : col4
	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1

}


foreach yvar of varlist  knowledge empt perceived_contagion perceived_mortality {

	sum `yvar' , d
	if `r(N)'!=0 {
	cap: estadd loc thisstat`count' = string(`r(mean)', "%12.2f"): col1
	cap: estadd loc thisstat`count' = string(`r(sd)', "%12.2f"): col2
	cap: estadd loc thisstat`count' = string(`r(p50)', "%9.0f"): col3
	cap: estadd loc thisstat`count' = `r(N)' : col4
	}

	/* Row Labels */
	
	loc thisvarlabel: variable label `yvar'
	local varlabels "`varlabels' "`thisvarlabel'" "
	loc statnames "`statnames' thisstat`count'"
	loc count = `count' + 1

}




/* Footnotes */

loc prehead "\begin{tabular}{l*{`columns'}{c}} \toprule"

loc postfoot "\bottomrule \end{tabular}"


esttab col* using "$tables/sumstats_experiment_main", booktabs cells(none)  nogap mtitle("Mean" "SD" "Median"  "Obs.") ///
 stats(`statnames', labels(`varlabels'))  prehead("`prehead'") postfoot("`postfoot'") compress wrap replace

eststo clear
